﻿/**************************************************************
 * Copyright gt1987. All rights reserved.
 * 
 * Author: guitao(guitao@eastmoney.com) 
 * Create Date: 2020/4/14 15:09:19
 * Description: ActiveCodeService
 *          
 * Revision History:
 *      Date         Author               Description
 *              
***************************************************************/

using gt.ShortMessage.Models;
using gt.ShortMessage.Utils;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace gt.ShortMessage.Services.Impls
{
    public class ActiveCodeService : IActiveCodeService
    {

        public ActiveCode GenerateActiveCode(string phone, string uniqueId, string businessId)
        {
            //此处在高并发场景下 需要进一步优化，随机code可能会相同
            var random = new Random(unchecked((int)DateTime.Now.Ticks));
            return new ActiveCode
            {
                BusinessId = businessId,
                Code = random.Next(1000, 9999).ToString(),
                Phone = phone,
                UniqueId = uniqueId,
                CreateTimeStamp = DateTimeHelper.ToTimeStamp(DateTime.Now),
                ExpiredTimeStamp = DateTimeHelper.ToTimeStamp(DateTime.Now.AddMinutes(10)),
            };
        }


    }
}
